package com.tencreat.common.core;


import com.tencreat.common.core.constants.HttpStatus;
import lombok.Data;

/**
 * @author Administrator
 */
@Data
public class HttpResult<T> {

    private int code;

    private String msg;

    private T data;

    private HttpResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private HttpResult(int code) {
        this(code, null, null);
    }

    private HttpResult(T data) {
        this(HttpStatus.SUCCESS, "", data);
    }

    private HttpResult(String msg) {
       this(HttpStatus.SUCCESS, msg, null);
    }

    public static <T> HttpResult<T> ok(){
        return new HttpResult<>(200);
    }

    public static <T> HttpResult<T> ok(T data){
        return new HttpResult<>(data);
    }

    public static <T> HttpResult<T> okMsg(String msg){
        return new HttpResult<>(msg);
    }
    public static <T> HttpResult<T> ok(int code, String msg){
        return new HttpResult<>(code, msg, null);
    }

    public static <T> HttpResult<T> error(){
        return new HttpResult<>(HttpStatus.ERROR);
    }

    public static <T> HttpResult<T> error(String msg){
        return new HttpResult<>(HttpStatus.ERROR, msg, null);
    }
    public static <T> HttpResult<T> error(int error, String msg){
        return new HttpResult<>(error, msg, null);
    }
}
